// sub_minsheng_sjts/sjts_page/sjts_page.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    pageNum: 1,
    repeat: 1,
    corpRole: wx.getStorageSync('userInfo').corpRole,
  },
  goBatch(e) {
    console.log(e)
    wx.setStorageSync('BusinessPushBatchNum', e.currentTarget.dataset.batchnum)
    wx.setStorageSync('BusinessPushBatchType', e.currentTarget.dataset.batchtype)
    wx.setStorageSync('BusinessPushBatchTime', e.currentTarget.dataset.batchtime)
   console.log(wx.getStorageSync('userInfo'),)
    if (wx.getStorageSync('userInfo').corpRole.includes('fir_admin')) {
      console.log(e,'到这里了')
      // 管理员
      wx.navigateTo({
        url: `/sub_minsheng_sjts/sjts_batch/sjts_batch?batchNum=${e.currentTarget.dataset.batchnum}&&batchType=${e.currentTarget.dataset.batchtype}&&batchNum=${e.currentTarget.dataset.batchnum}`,
      })
    } else {
      // 传呼员
      wx.navigateTo({
        url: `/sub_minsheng_sjts/sjts_batch_why/sjts_batch_why?batchNum=${e.currentTarget.dataset.batchnum}&&batchType=${e.currentTarget.dataset.batchtype}&&batchNum=${e.currentTarget.dataset.batchnum}`,
      })
    }

  },
  async getList() {
    let params = {
      pageNum: this.data.pageNum,
      pageSize: 8
    }
    if (wx.getStorageSync('userInfo').corpRole.includes('fir_admin')) {
      console.log(params,'走这里1')
      
      const res = await getApp().globalData.request(
        "/businessPush/getBatchInfo", params,
        "POST",
      );
      console.log(res, '接口返回的值22')
      let list = res.data.list
      list.forEach(element => {
        this.data.dataList.push(element)
      });
      this.setData({
        dataList: this.data.dataList,
      })
      this.data.pageNum = this.data.pageNum + 1
    } else {
      console.log('走这里2')
      const res = await getApp().globalData.request(
        "/businessPush/getCommissionerBatchInfo", params,
        "POST",
      );
      console.log(res, 'resres')
      let list = res.data.list
      list.forEach(element => {
        this.data.dataList.push(element)
      });
      this.setData({
        dataList: this.data.dataList,
      })
      this.data.pageNum = this.data.pageNum + 1
    }

  },
  scrollBottom() {
    if (this.data.repeat == this.data.pageNum) {
      this.data.repeat = this.data.repeat + 1
      this.getList()
    }


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options,'options')
    this.scrollBottom()
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})